home *** CD-ROM | disk | FTP | other *** search
/ The Sunday Times: The Month 2004 August / The Sunday Times - The Month 2004-08.iso / pc / engine / modules / text_art_nolink.swf / scripts / frame_1 / DoAction.as
Encoding:
Text File  |  2004-06-24  |  12.5 KB  |  434 lines

  1. function loadImage(mc, node, extrapath)
  2. {
  3.    var _loc3_ = extrapath;
  4.    if(_loc3_ == null)
  5.    {
  6.       _loc3_ = "";
  7.    }
  8.    var strDefaultPath = Tardis.ASSETS_FOLDER + "images/" + Tardis.ActiveSection.id + "/";
  9.    var _loc1_ = node.firstChild.nodeValue;
  10.    var _loc2_ = node.attributes.path;
  11.    if(_loc2_ != null)
  12.    {
  13.       _loc1_ = _loc2_ + _loc1_;
  14.    }
  15.    else
  16.    {
  17.       _loc1_ = strDefaultPath + _loc3_ + _loc1_;
  18.    }
  19.    if(strPathPrefix == null)
  20.    {
  21.       strPathPrefix = "";
  22.    }
  23.    mc.loadMovie(strPathPrefix + _loc1_);
  24. }
  25. function addLink(mc)
  26. {
  27.    Links[mc.link] = mc;
  28. }
  29. function getMCfromLink(Item)
  30. {
  31.    var _loc1_ = Item;
  32.    if(Links[_loc1_] == null)
  33.    {
  34.       var _loc2_ = [];
  35.       while(_loc1_ != sideMenu.ItemHome)
  36.       {
  37.          _loc2_.unshift(_loc1_._name.split("_").pop());
  38.          _loc1_ = _loc1_._parent._parent;
  39.       }
  40.       var _loc3_ = _loc2_.join("/");
  41.       Links[_loc1_] = Links[_loc3_];
  42.    }
  43.    return Links[_loc1_];
  44. }
  45. function removeLinkListener()
  46. {
  47.    Tardis.sideMenu.EB.removeListener(this);
  48. }
  49. function init()
  50. {
  51.    build();
  52. }
  53. function build()
  54. {
  55.    var strID = Tardis.ActiveSection.id;
  56.    var _loc2_ = Tardis.Colors;
  57.    strSECTION_COLOR = _loc2_.getString(strID);
  58.    SECTION_COLOR = _loc2_.getHex(strID);
  59.    strSECTION_COLOR50 = _loc2_.getString(strID + "50");
  60.    SECTION_COLOR50 = _loc2_.getHex(strID + "50");
  61.    DEFAULT_COLOR = _loc2_.getHex("default");
  62.    DEFAULT_COLOR50 = _loc2_.getString("default50");
  63.    modWidth = nodeData.byName("dimensions").attributes.width;
  64.    txtWidth = modWidth - 12;
  65.    modHeight = nodeData.byName("dimensions").attributes.height;
  66.    loadImage(mc_img_0,nodeData.byName("image"),IMAGE_PATH);
  67.    titlevar = false;
  68.    if(nodeData.byName("title").getText() != null || nodeData.byName("title2").getText() != null || nodeData.byName("title3").getText() != null)
  69.    {
  70.       var strTitle = "<FONT COLOR=\"" + strSECTION_COLOR + "\">" + nodeData.byName("title").getText() + " </FONT>";
  71.       strTitle += "<FONT COLOR=\"" + strSECTION_COLOR50 + "\"> " + nodeData.byName("title2").getText() + " </FONT>";
  72.       strTitle += "<FONT COLOR=\"" + DEFAULT_COLOR50 + "\"> " + nodeData.byName("title3").getText() + " </FONT>";
  73.       titleFF.htmlText = strTitle;
  74.       titleFF.resize();
  75.       titleVar = true;
  76.    }
  77.    title2var = false;
  78.    var strByline = nodeData.byName("byline").getText();
  79.    if(strByline != null)
  80.    {
  81.       title2FF.htmlText = strByline;
  82.       title2FF.textColor = DEFAULT_COLOR;
  83.       title2FF.resize();
  84.       title2var = true;
  85.    }
  86.    this.attachMovie("scrollContentMC","sMC",++depth);
  87.    sMC._visible = false;
  88.    sMC.bodyFF._width = sMC.body2FF._width = txtWidth;
  89.    var ndBody = nodeData.byName("body");
  90.    if(ndBody.getText() != null)
  91.    {
  92.       sMC.bodyFF.htmlText = parseBoldTags(ndBody.getText());
  93.       sMC.bodyFF.textColor = DEFAULT_COLOR;
  94.       sMC.bodyFF.autoSize = true;
  95.       sMC.bodyFF._y = CONTENT_POS;
  96.       CONTENT_POS += sMC.bodyFF._height + 12;
  97.    }
  98.    var ndBody2 = nodeData.byName("body2");
  99.    if(ndBody2.getText() != null)
  100.    {
  101.       sMC.body2FF.htmlText = parseBoldTags(ndBody2.getText());
  102.       sMC.body2FF.textColor = DEFAULT_COLOR;
  103.       sMC.body2FF.autoSize = true;
  104.       sMC.body2FF._y = CONTENT_POS;
  105.       CONTENT_POS += sMC.body2FF._height;
  106.    }
  107.    var _loc1_ = bodyLinkMC;
  108.    var _loc3_ = nodeData.byName("bodylink");
  109.    var strLabel1 = _loc3_.byName("label1").getText();
  110.    var strLabel2 = _loc3_.byName("label2").getText();
  111.    if(strLabel1 != null || strLabel2 != null)
  112.    {
  113.       _loc1_.contentFF.htmlText = strLabel1;
  114.       _loc1_.contentFF.textColor = SECTION_COLOR;
  115.       _loc1_.content2FF.htmlText = strLabel2;
  116.       _loc1_.content2FF.textColor = SECTION_COLOR;
  117.       _loc1_.link = _loc3_.attributes.link;
  118.       if(_loc3_.attributes.promo != null)
  119.       {
  120.          _loc1_.promolink = _loc3_.byName("link").getText();
  121.       }
  122.       else
  123.       {
  124.          _loc1_.promolink = 0;
  125.       }
  126.       _loc1_.contentFF.autoSize = true;
  127.       _loc1_.content2FF.autoSize = true;
  128.       _loc1_.btn._width = _loc1_.contentFF._width + _loc1_.arrowMC._x - 20;
  129.       _loc1_.arrowMC._x = _loc1_.contentFF._x + _loc1_.contentFF._width + 1;
  130.    }
  131.    else
  132.    {
  133.       _loc1_._height = 0;
  134.       _loc1_._visible = false;
  135.       _loc1_.arrowMC._visible = false;
  136.    }
  137.    intervalID = setInterval(checkLoad,100);
  138.    onComplete();
  139. }
  140. function checkLoad()
  141. {
  142.    if(mc_img_0._height > 0)
  143.    {
  144.       TEXT_POS = mc_img_0._x + mc_img_0._height - 4;
  145.       if(titlevar)
  146.       {
  147.          titleFF._y = TEXT_POS;
  148.          TEXT_POS += titleFF._height - 7;
  149.       }
  150.       if(title2var)
  151.       {
  152.          title2FF._y = TEXT_POS;
  153.          TEXT_POS += title2FF._height - 9;
  154.       }
  155.       var _loc1_ = nodeData.byName("bodylink").byName("label1").getText();
  156.       var strLabel12 = nodeData.byName("bodylink").byName("label2").getText();
  157.       if(_loc1_ != null || strLabel2 != null)
  158.       {
  159.          heightToTest = modHeight - TEXT_POS - bodyLinkMC.contentFF._height - bodyLinkMC.content2FF._height - 10;
  160.       }
  161.       else
  162.       {
  163.          heightToTest = modHeight - TEXT_POS - 12;
  164.       }
  165.       if(sMC._height > heightToTest)
  166.       {
  167.          attachMovie("FScrollPaneSymbol","contentScroll",++depth);
  168.          attachMovie("MaskerMC","MaskerMC",++depth);
  169.          contentScroll._x = 7;
  170.          contentScroll._y = TEXT_POS;
  171.          if(_loc1_ != null)
  172.          {
  173.             contentScroll.setSize(modWidth,modHeight - TEXT_POS - bodyLinkMC.contentFF._height - bodyLinkMC.content2FF._height - 10);
  174.          }
  175.          else
  176.          {
  177.             contentScroll.setSize(modWidth,modHeight - TEXT_POS - 12);
  178.          }
  179.          contentScroll.setHScroll(false);
  180.          contentScroll.setScrollContent(sMC);
  181.          MaskerMC._x = 6;
  182.          MaskerMC._y = TEXT_POS - MaskerMC._height + 10;
  183.          MaskerMC._width = contentScroll._width - 17;
  184.          MaskerMC._height = 5;
  185.       }
  186.       else
  187.       {
  188.          sMC._x = 8;
  189.          sMC._y = TEXT_POS;
  190.          if(sMC.txtbodyLink._y < modHeight - sMC.txtbodyLink.height - 38)
  191.          {
  192.             sMC.txtbodyLink._y = modHeight - sMC.txtbodyLink.height - 38;
  193.          }
  194.       }
  195.       _visible = true;
  196.       sMC._visible = true;
  197.       clearInterval(intervalID);
  198.    }
  199. }
  200. function txtOver(mc)
  201. {
  202.    var _loc1_ = mc;
  203.    if(_loc1_.promolink == 0)
  204.    {
  205.       Tardis.sideMenu.doOver(_loc1_.link);
  206.    }
  207.    bodyLinkMC.contentFF.textColor = SECTION_COLOR;
  208.    bodyLinkMC.arrowMC.gotoAndStop("over");
  209. }
  210. function parseBoldTags(str)
  211. {
  212.    var _loc1_ = str;
  213.    var _loc2_ = _loc1_.indexOf("<b>");
  214.    if(_loc2_ != -1)
  215.    {
  216.       var _loc3_ = _loc1_.indexOf("</b>");
  217.       var word = _loc1_.substring(_loc2_ + 3,_loc3_);
  218.       var beginning = _loc1_.substring(0,_loc2_);
  219.       var end = _loc1_.substring(_loc3_ + 4);
  220.       return beginning + "<font face=\'FranklinGotURWTDem\'>" + word + "</font>" + parseBoldTags(end);
  221.    }
  222.    return _loc1_;
  223. }
  224. function txtOut(mc)
  225. {
  226.    var _loc1_ = mc;
  227.    if(_loc1_.promolink == 0)
  228.    {
  229.       Tardis.sideMenu.doOut(_loc1_.link);
  230.    }
  231.    bodyLinkMC.contentFF.textColor = SECTION_COLOR50;
  232.    bodyLinkMC.arrowMC.gotoAndStop("off");
  233. }
  234. function txtUp(mc)
  235. {
  236.    var _loc1_ = mc;
  237.    if(_loc1_.promolink != 0)
  238.    {
  239.       Tardis.webPageOpen(_loc1_.promolink);
  240.    }
  241.    else
  242.    {
  243.       Tardis.sideMenu.doUp(_loc1_.link);
  244.    }
  245. }
  246. function doOver(num)
  247. {
  248.    if(bodyLinkMC.link == num)
  249.    {
  250.       bodyLinkMC.contentFF.textColor = SECTION_COLOR;
  251.       bodyLinkMC.arrowMC.gotoAndStop("over");
  252.    }
  253. }
  254. function doOut(num)
  255. {
  256.    if(bodyLinkMC.link == num)
  257.    {
  258.       bodyLinkMC.contentFF.textColor = SECTION_COLOR50;
  259.       bodyLinkMC.arrowMC.gotoAndStop("off");
  260.    }
  261. }
  262. function searchandreplace(the_string, search_string, replace_string, occurrences, backward)
  263. {
  264.    var _loc1_ = the_string;
  265.    var _loc3_ = search_string;
  266.    if(_loc3_ == replace_string)
  267.    {
  268.       return _loc1_;
  269.    }
  270.    var found = 0;
  271.    if(backward == true)
  272.    {
  273.       var _loc2_ = _loc1_.lastIndexOf(_loc3_);
  274.       while(_loc2_ >= 0)
  275.       {
  276.          found++;
  277.          var start_string = _loc1_.substr(0,_loc2_);
  278.          var end_string = _loc1_.substr(_loc2_ + _loc3_.length);
  279.          _loc1_ = start_string + replace_string + end_string;
  280.          _loc2_ = _loc1_.lastIndexOf(_loc3_,start_string.length);
  281.          if(found == occurrences)
  282.          {
  283.             _loc2_ = -1;
  284.          }
  285.       }
  286.    }
  287.    else
  288.    {
  289.       _loc2_ = _loc1_.indexOf(_loc3_);
  290.       while(_loc2_ >= 0)
  291.       {
  292.          found++;
  293.          var start_string = _loc1_.substr(0,_loc2_);
  294.          var end_string = _loc1_.substr(_loc2_ + _loc3_.length);
  295.          _loc1_ = start_string + replace_string + end_string;
  296.          _loc2_ = _loc1_.indexOf(_loc3_,_loc2_ + replace_string.length);
  297.          if(found == occurrences)
  298.          {
  299.             _loc2_ = -1;
  300.          }
  301.       }
  302.    }
  303.    return _loc1_;
  304. }
  305. function tagStack(aString)
  306. {
  307.    var error = false;
  308.    var tagArray = [];
  309.    var validTags = ["a","b","i","u","font","p"];
  310.    var tStringArray = aString.split("<");
  311.    var _loc3_ = 1;
  312.    while(_loc3_ < tStringArray.length)
  313.    {
  314.       var _loc1_ = "<" + tStringArray[_loc3_].slice(0,tStringArray[_loc3_].indexOf(">") + 1);
  315.       var shortForm = _loc1_.indexOf(" ") <= -1 ? _loc1_ : _loc1_.slice(0,_loc1_.indexOf(" ")) + ">";
  316.       var tagOnly = shortForm.indexOf("/") <= -1 ? shortForm.slice(1,-1) : shortForm.slice(2,-1);
  317.       isValidTag = false;
  318.       for(var j in validTags)
  319.       {
  320.          if(validTags[j] == tagOnly)
  321.          {
  322.             isValidTag = true;
  323.             break;
  324.          }
  325.       }
  326.       if(isValidTag)
  327.       {
  328.          if(_loc1_.charAt(1) == "/")
  329.          {
  330.             var _loc2_ = tagArray.pop();
  331.             lastTagShort = _loc2_.indexOf(" ") <= -1 ? _loc2_ : _loc2_.slice(0,_loc2_.indexOf(" ")) + ">";
  332.             lastTagShort = lastTagShort.indexOf("/") <= -1 ? lastTagShort.slice(1,-1) : lastTagShort.slice(2,-1);
  333.             if(lastTagShort != tagOnly)
  334.             {
  335.                error = true;
  336.                break;
  337.             }
  338.          }
  339.          else
  340.          {
  341.             tagArray.push(_loc1_);
  342.          }
  343.       }
  344.       _loc3_ = _loc3_ + 1;
  345.    }
  346.    if(!error)
  347.    {
  348.       return tagArray;
  349.    }
  350.    return -1;
  351. }
  352. function fixText(textString)
  353. {
  354.    var _loc3_ = textString;
  355.    var _loc1_ = searchandreplace(_loc3_,String.fromCharCode(13)," <br>");
  356.    _loc1_ = searchandreplace(_loc3_,"\n"," <br>");
  357.    _loc1_ = searchandreplace(_loc3_,"\r"," <br>");
  358.    _loc1_ = searchandreplace(_loc1_,String.fromCharCode(9)," ");
  359.    var _loc2_ = _loc1_.split(" ");
  360.    return _loc2_;
  361. }
  362. function flowText(textString, arrayOfTextFields)
  363. {
  364.    var textArray = fixText(textString);
  365.    var currentWordIndex = 0;
  366.    var currentFieldIndex = 0;
  367.    var maxWordIndex = textArray.length;
  368.    var timeArray = [];
  369.    var leftOverTags = "";
  370.    var i;
  371.    var lastWord = 0;
  372.    for(i in arrayOfTextFields)
  373.    {
  374.       eval(arrayOfTextFields[i]).html = false;
  375.       eval(arrayOfTextFields[i]).text = "";
  376.       eval(arrayOfTextFields[i]).htmlText = "";
  377.    }
  378.    do
  379.    {
  380.       if(currentWordIndex < maxWordIndex)
  381.       {
  382.          var field = eval(arrayOfTextFields[currentFieldIndex]);
  383.          var tempString = "";
  384.          field.html = true;
  385.          if(textArray[currentWordIndex].indexOf("<br>") != -1)
  386.          {
  387.             textArray[currentWordIndex] = searchandreplace(textArray[currentWordIndex],"<br>","");
  388.          }
  389.          i = currentWordIndex;
  390.          while(i < maxWordIndex)
  391.          {
  392.             var newWord = textArray[i];
  393.             newWord = newWord != "<br>" ? newWord + " " : newWord;
  394.             tempString += newWord;
  395.             field.htmlText = "";
  396.             field.htmlText = tempString;
  397.             if(field.maxscroll > 1)
  398.             {
  399.                lastWord = i;
  400.                break;
  401.             }
  402.             i++;
  403.          }
  404.       }
  405.       else
  406.       {
  407.          return true;
  408.       }
  409.       field.htmlText = "";
  410.       var endAt = i;
  411.       field.htmlText = leftOverTags + textArray.slice(currentWordIndex,endAt).join(" ");
  412.       leftOverTags = tagStack(textArray.slice(0,endAt).join(" ")).join("");
  413.       currentWordIndex = endAt;
  414.       currentFieldIndex++;
  415.    }
  416.    while(currentFieldIndex <= arrayOfTextFields.length);
  417.    
  418.    var leftOverText = textArray.slice(lastWord,textArray.length).join(" ");
  419.    return leftOverText;
  420. }
  421. _visible = false;
  422. Links = {};
  423. Tardis.sideMenu.EB.addListener(this);
  424. SCROLLBOX_INIT_POS = 55;
  425. TEXT_POS = 30;
  426. CONTENT_POS = 0;
  427. onReady();
  428. this.onUnload = function()
  429. {
  430.    clearInterval(intervalID);
  431.    removeLinkListener();
  432. };
  433. stop();
  434.